﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script type="text/javascript">
    var currRowId = 1;
    $(function () {
        initControl();
        gridList();
    });
    function initControl() {
        $('select').bindSelect();
    }
    function gridList() {
        $('#btn_add').removeClass("disabled");
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/BOM/Manufacture/GetStampingKitJson",
            postData: { keyword: $("#txt_keyword").val() },
            height: $(window).height() - 118,
            colModel: [
                { label: '合件编号', name: 'CombineNO', width: 120, align: 'left', sortable: false, frozen: true },
                { label: '合件名称', name: 'CombineName', width: 200, align: 'left', sortable: false, frozen: true },
                { label: '零件编号', name: 'FProductionNO', width: 120, align: 'left', sortable: false },
                { label: '零件名称', name: 'FProductionName', width: 200, align: 'left', sortable: false },
                { label: '数量', name: 'FProductionSum', width: 70, align: 'center', sortable: false },
                { label: '生产单位编码', name: 'ProductUnit', width: 90, align: 'center', sortable: false },
                { label: '生产单位', name: 'ProductUnitName', width: 70, align: 'center', sortable: false },
                { label: '生产车间编码', name: 'ProduWorkshop', width: 90, align: 'center', sortable: false },
                { label: '生产车间', name: 'ProduWorkshopName', width: 70, align: 'center', sortable: false },
                { label: '材料分类', name: 'MaterialNO', width: 70, align: 'center', sortable: false },
                { label: '材料牌号', name: 'MaterialCode', width: 70, align: 'center', sortable: false },
                { label: '材料规格(mm)', name: 'MaterialSizes', width: 70, align: 'center', sortable: false },
                { label: '标准编号', name: 'StandardNumber', width: 70, align: 'center', sortable: false },
                { label: '特殊要求', name: 'MaterialDemand', width: 70, align: 'center', sortable: false },
                { label: '毛坯尺寸(mm)', name: 'RoughsSize', width: 90, align: 'center', sortable: false },
                { label: '毛坯重量(Kg)', name: 'LRoughsWeight', width: 90, align: 'center', sortable: false },
                { label: '材料定额(Kg)', name: 'Lconsume', width: 90, align: 'center', sortable: false },
                { label: '零件净重(Kg)', name: 'LsNetWeight', width: 90, align: 'center', sortable: false },
                { label: '利用率(%)', name: 'LUtilization', width: 70, align: 'center', sortable: false },
                { label: '利废零件', name: 'WasteFProductionNO', width: 70, align: 'center', sortable: false },
                { label: '利废单位', name: 'WasteUnitName', width: 70, align: 'center', sortable: false },
                { label: '利废车间', name: 'WasteWorkshopName', width: 70, align: 'center', sortable: false },
                { label: '比例(%)', name: 'WasteProportion', width: 70, align: 'center', sortable: false },
                { label: '代用材料', name: 'SubstitMaterial', width: 70, align: 'center', sortable: false },
                { label: '备注说明', name: 'Note', width: 200, align: 'left', sortable: false },
                { label: 'CombineID', name: 'CombineID', hidden: true }
            ],
            pager: "#gridPager",
            sortname: 'CombineNO asc,FProductionNO asc',
            viewrecords: true,  //是否显示行数
            rownumWidth: 40,
            gridComplete: function () {

            },
            loadComplete: function () {
                hackHeight("#gridList");
                $gridList.jqGrid('setSelection', currRowId);
            },
            onSelectRow: function (rowid) {
                currRowId = rowid;
                $('#btn_edit').removeClass("disabled");
                $('#btn_remove').removeClass("disabled");
            },
            onPaging: function (page_btn) {
                currRowId = 1;
            }
        });
        $("#btn_search").click(function () {
            reloadGrid();
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList.jqGrid('setFrozenColumns');
    }
    function reloadGrid() {
        $("#gridList").jqGrid('setGridParam', {
            postData: { keyword: $("#txt_keyword").val() },
        }).trigger('reloadGrid');
    }
    function btn_add() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/BOM/Manufacture/StampingKitInput"
        });
    }
    function btn_edit() {
        var $gridList = $("#gridList");
        var rowData = $gridList.jqGrid('getRowData', currRowId);
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/BOM/Manufacture/StampingKitInput?status=U&number=" + rowData.CombineID
        });
    }
    function btn_remove() {
        var $gridList = $("#gridList");
        var rowData = $gridList.jqGrid('getRowData', currRowId);
        $.modalConfirm("注：您确定要【删除】编号为“" + rowData.CombineNO + "”的合件数据吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/BOM/Manufacture/SubmitStampingKitInputForm?status=D",
                    param: { CombineNO: rowData.CombineNO },
                    success: function () {
                        reloadGrid();
                    }
                })
            }
        });
    }
    function btn_export() {
        var url = "/Common/ExcelExport?" + init_sql();
        location.href = url;
    }
    function init_sql() {
        var tablename = "V_CLDE_31_TC_CLDEerialCombine";
        var condition = "UseUnit='@FriendStar.Code.Configs.GetValue("UseUnit")'";
        var cols = [];
        //获取列字段
        var colModel = $("#gridList").jqGrid('getGridParam', 'colModel');
        for (var i = 0; i < colModel.length; i++) {
            var columnHidden = colModel[i].hidden;
            var columnName = colModel[i].name;
            var columnLabel = colModel[i].label;
            if (columnHidden == false && columnName != "rn" && columnName != "") {
                if (columnLabel != '') {
                    cols.push(columnName + ' [' + columnLabel.replace(/<[^>]+>/g, "") + ']');
                } else {
                    cols.push(columnName);
                }
            }
        }
        if ($('#txt_keyword').val() != '') {
            condition += " AND (CombineNO LIKE '%" + $('#txt_keyword').val() + "%' OR CombineName LIKE '%" + $('#txt_keyword').val() + "%')";
        }
        var sql = "SELECT " + cols.join(',') + " FROM " + tablename + " WHERE " + condition + " ORDER BY CombineNO ASC,FProductionNO ASC";
        return "sql=" + sql;
    }
</script>
<div id="layout" style="height: 100%; width: 100%;">
    <form id="form1">
        <div style="padding: 12px 0 5px 0; padding-left: 15px; border-bottom: 1px solid #ccc;" class="line-table input-width-140">
            <div class="btn-group" style="margin-top:-9px;">
                合件编号<br /><input id="txt_keyword" name="" type="text" class="form-control required" /> &nbsp;
            </div>
            <div class="btn-group" style="">
                <a id="btn_search" class="btn btn-primary center-block" onclick=""><span class="glyphicon glyphicon-search"></span> 检索</a>
            </div>
            <div class="btn-group" style="float:right;">
                <a id="btn_reload" class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span> 刷新</a>
                <a id="btn_add" class="btn btn-primary center-block disabled" onclick="btn_add()"><span class="glyphicon glyphicon-plus"></span> 新增</a>
                <a id="btn_edit" class="btn btn-primary center-block disabled" onclick="btn_edit()"><span class="glyphicon glyphicon-edit"></span> 修改</a>
                <a id="btn_remove" class="btn btn-primary center-block disabled" onclick="btn_remove()"><span class="glyphicon glyphicon-trash"></span> 删除</a>
                <a id="btn_export" class="btn btn-primary center-block" onclick="btn_export()"><span class="glyphicon glyphicon-download"></span> 导出</a>
            </div>
        </div>
    </form>
    <div style="">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
</div>

